package org.testis.gui.mvc.model.testdesign;

import org.testis.gui.mvc.model.*;
import org.testis.gui.mvc.controller.testdesign.LabelSettingsController;
import org.testis.utils.tree.DefaultMutableLabelNode;
import org.testis.utils.tree.DefaultMutableLabelNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import org.testis.utils.tree.LabelTreeNode;

/**
 *
 * @author nurhat
 */
public class LabelSettingsModel extends AbstractModel {

    private DefaultMutableLabelNode m_rootNode = null;
    private DefaultMutableLabelNode m_selectedNode = null;
    private TreePath m_selectionTreePath = null;
    private String m_lastError = "";
    private Boolean m_viewVisibility = false;

    public LabelSettingsModel() {
        super();
    }

    public Boolean getViewVisibility() {
        return m_viewVisibility;
    }

    public void setViewVisibility(Boolean val) {
        if (val != null && val) {
            firePropertyChange(LabelSettingsController.SHOW_VIEW_PROPERTY, false,
                    true);
        }
    }

    public void setLoadTree(DefaultMutableLabelNode value) {
        if (value == null) {
            return;
        }
        DefaultMutableLabelNode old = m_rootNode;
        m_rootNode = value;
        firePropertyChange(LabelSettingsController.TREE_LOAD_PROPERTY, old,
                m_rootNode);
    }

    public void setRefreshTree(Boolean refresh) {
        if (refresh != null && refresh) {
            firePropertyChange(LabelSettingsController.TREE_REFRESH_PROPERTY,
                    false, true);
        }
    }

    public DefaultMutableLabelNode getSelectedNode() {
        return m_selectedNode;
    }

    public void setSelectedNode(DefaultMutableLabelNode value) {
        DefaultMutableLabelNode oldValue = m_selectedNode;
        m_selectedNode = value;
        firePropertyChange(LabelSettingsController.SELECTED_NODE_PROPERTY,
                oldValue,
                value);
    }

    public String getLastError() {
        return m_lastError;
    }

    public void setLastError(String val) {
        if (val == null) {
            val = "";
        }
        m_lastError = val;
        firePropertyChange(LabelSettingsController.ERROR_PROPERTY, null,
                val);
    }

    /**
     * @return the m_expandTreePath
     */
    public TreePath getSelectionTreePath() {
        return m_selectionTreePath;
    }

    /**
     * @param val the m_expandTreePath to set
     */
    public void setSelectionTreePath(TreePath value) {
        if (value == null) {
            return;
        }
        TreePath oldValue = m_selectionTreePath;
        this.m_selectionTreePath = value;
        firePropertyChange(LabelSettingsController.SELECTION_TREE_PATH_PROPERTY,
                oldValue,
                value);
    }
}
